package CRUD;

import CRUD.User;
import CRUD.UserDao;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import java.sql.SQLException;

public class TestUser {
    //创建UserDao对象
    private UserDao userDao;

    @Before
    public void setUp() {
        userDao = new UserDao();
    }

    @After
    public void end() {
        userDao = null;
    }

    //测试插入学生信息
    @Test
    public void addUserTest() throws SQLException {
        //创建User对象user
        User user = new User(321119, "繁花", "男",
                25, "医学系");
        //调用插入学生信息方法
        userDao.addUser(user);
        //创建新的User对象newUser
        User newUser = userDao.getUserBySno(user.getSno());
        //断言Sno
        Assert.assertEquals(user.getSno(), newUser.getSno());
    }


    //测试删除学生信息
    @Test
    public void deleteUserTest() {
        User user=new User();
        user.setSno(321119);
        userDao.deleteUser(user.getSno());
    }


    //测试更新学生信息
    @Test
    public void updateTest() {
        User user = new User(321118,"阿看","男",22,"物理系");
        userDao.updateUser(user);
    }

    //测试查询学生信息
    @Test
    public void getUserBySnoTest(){
        User user;
       user= userDao.getUserBySno(321118);
        System.out.println(user.getSno()+"\t"+user.getSname()+"\t"+
                user.getSsex()+"\t"+user.getSage()+"\t"+user.getSdept());
    }
}
